var a = {
	b: 123,
	c: '456',
	e: '789',
	f: {
		g: 'abin'
	}
};
var str = `a{a.b}aa{a.c}aa {a.d}aaaa{a.f.g}`;
// => 'a123aa456aa {a.d}aaaa'
const fn1 = (str, obj) => {
	let res = '';
	// 标志位，标志前面是否有{
	let flag = false;
	let start;
	for (let i = 0; i < str.length; i++) {
		if (str[i] === '{') {
			flag = true;
			start = i + 1;
			continue;
		}
		if (!flag) res += str[i];
		else {
			if (str[i] === '}') {
				flag = false;
				res += match(str.slice(start, i), obj);
			}
		}
	}
	return res;
};
// 对象匹配操作
const match = (str, obj) => {
	const keys = str.split('.').slice(1);
	let index = 0;
	let o = obj;
	while (index < keys.length) {
		const key = keys[index];
		if (!o[key]) {
			return `{${str}}`;
		} else {
			o = o[key];
		}
		index++;
	}
	return o;
};
console.log(fn1(str, a))
